package ${package.Service}.test;

import ${package.Entity}.${table.entityName};
import ${package.Service}.${table.serviceName};
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rt.easyjavabase.utils.base.PageDto;


/**
 * ${table.comment}测试
 *
 * @author:${author}
 */
@TestInstance(value = TestInstance.Lifecycle.PER_CLASS)
public class ${table.entityName}Test {
    @Autowired
    private ${table.entityName}Service ${table.entityPath}Service;

    @BeforeAll
    public void beforeAllTests() {
        //LOG.info("Before all tests");
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ${table.entityPath}Service = (${table.entityName}Service)context.getBean("${table.entityPath}Service");
    }

    @AfterAll
    static void afterAllTests() {
        //LOG.info("After all tests");
    }

    /**
     * 获取${table.comment}
     */
    @Test
    public void getById(){
        int id = 1385204;
        ${table.entityName} ${table.entityPath} = ${table.entityPath}Service.getById(id);
        System.out.println(${table.entityPath}.getId());
    }

    /**
     * 获取${table.comment}分页
     *
     */
    @Test
    public void page(){
        PageDto pageDto = new PageDto();

        Page<${table.entityName}> page = new Page<>(pageDto.getPageCurrent(), pageDto.getPageSize());
        page.addOrder(new OrderItem().setColumn(pageDto.getSortColumn()).setAsc(pageDto.getAsc()));

        ${table.entityName} ${table.entityPath} = new ${table.entityName}();
        ${table.entityPath}.setDeleteflag(0);
        QueryWrapper<${table.entityName}> queryWrapper=new QueryWrapper<>(${table.entityPath});
        page= ${table.entityPath}Service.page(page, queryWrapper);

        System.out.println("page.getRecords():"+page.getRecords());
        System.out.println("page.getTotal():"+page.getTotal());
    }

    /**
     * 添加${table.comment}
     */
    @Test
    public void add(){
        ${table.entityName} ${table.entityPath} = new ${table.entityName}();
        //....
        ${table.entityPath}Service.save(${table.entityPath});
        System.out.println(${table.entityPath}.getId());
    }
    /**
     * 更新${table.comment}
     */
    @Test
    public void update(){
        int id = 1385204;
        ${table.entityName} ${table.entityPath} = ${table.entityPath}Service.getById(id);
        //....
        ${table.entityPath}Service.updateById(${table.entityPath});
        System.out.println(${table.entityPath}.getId());
    }
    /**
     * 逻辑删除${table.comment}
     */
    @Test
    public void del(){
        int id = 1385204;
        ${table.entityName} ${table.entityPath} = ${table.entityPath}Service.getById(id);
        ${table.entityPath}.setDeleteflag(1);
        ${table.entityPath}Service.updateById(${table.entityPath});
        //.....
        System.out.println(${table.entityPath}.getId());
        System.out.println(${table.entityPath}.getDeleteflag());

    }
}
